#include "compile_run.hpp"
#include "../Comm/Httplib.hpp"

using namespace httplib;
using namespace ns_compile_run;


void Usage(std::string proc)
{
    std::cout << proc << " + port"  << std::endl;
}
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(1);
    }
    Server svr;
    // svr.Get("/hhh", [](const Request& req, Response& resp){
    //     resp.set_content("hehehe张三hehe", "text/plain;charset=utf-8");
    // });
    svr.Post("/compile_run", [](const Request& req, Response& resp){
        std::string in_json = req.body;
        std::string out_json;
        Compile_Run::Start(in_json, &out_json);
        resp.set_content(out_json, "application/json;charset=utf-8");
    });

    svr.listen("0.0.0.0", std::stoi(argv[1]));

    // Json::Value in_json;
    // in_json["code"] = R"(#include<iostream>
    // int main(){
    // std::cout << "hello yss" << std::endl;
    // return 0;
    // })";
    // in_json["input"] = "";
    // in_json["cpu_limit"] = 2;
    // in_json["mem_limit"] = 30*1024;
    // Json::StyledWriter writer;
    // std::string in = writer.write(in_json);
    // std::string out;

    // Compile_Run::Start(in, &out);

    // std::cout << out;

    // Compiler::IsCompiler("code");
    // int ret = Run::Runner("code", 2, 30*10240);

    return 0;
}